package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dao.OrderPageDTO;
import com.sky.dao.OrderQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderSubmitVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    Page<Orders> pageQuery(OrderPageDTO orderPageDTO);

    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    @Select("select * from orders where number = #{outTradeNo} and user_id = #{userId}")
    Orders getByNumberAndUserId(String outTradeNo, Long userId);

    void update(Orders orders);

    Page<Orders> list(OrderQueryDTO orderQueryDTO);

    @Select("select count(*) from orders where status = #{status}")
    int countByStatus(int status);

    @Select("select count(*) from orders")
    Integer countAllOrders();

    @Select("select count(*) from orders where order_time >= #{begin} and order_time <= #{end}")
    Integer countAllOrdersWithDate(LocalDateTime begin, LocalDateTime end);

    @Select("select count(*) from orders where status = #{status} and order_time >= #{begin} and order_time <= #{end}")
    Integer countByStatusWithDate(Integer status, LocalDateTime begin, LocalDateTime end);

    /**
     * 根據狀態和下單時間查詢訂單
     */
    @Select("select * from orders where status = #{status} and order_time <= #{orderTime}")
    List<Orders> getByStatusAndOrderTime(Integer status, LocalDateTime orderTime);
}
